package game.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagLayout;
import java.awt.Paint;
import java.awt.Toolkit;

import static java.awt.GraphicsDevice.WindowTranslucency.*;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public abstract class View extends JFrame {

	enum ALIGN {
		CENTERONSCREEN
	}

	// Determine what the default GraphicsDevice can support.
	GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	GraphicsDevice gd = ge.getDefaultScreenDevice();
	boolean isUniformTranslucencySupported = gd
			.isWindowTranslucencySupported(TRANSLUCENT);
	boolean isPerPixelTranslucencySupported = gd
			.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT);
	boolean isShapedWindowSupported = gd
			.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT);
	private byte SplitScreenX = 0;
	private byte SplitScreenY = 0;

	public View() {
		JFrame.setDefaultLookAndFeelDecorated(true);
		
		setBackground(new Color(0, 0, 0, 0));
		setSize(new Dimension(300, 200));
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JPanel panel = new JPanel() {
			@Override
			protected void paintComponent(Graphics g) {
				if (g instanceof Graphics2D) {
					final int R = 240;
					final int G = 240;
					final int B = 240;

					Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B,
							0), 0.0f, getHeight(), new Color(R, G, B, 255),
							true);
					Graphics2D g2d = (Graphics2D) g;
					g2d.setPaint(p);
					g2d.fillRect(0, 0, getWidth(), getHeight());
				}
			}
		};
		setContentPane(panel);
		setLayout(new GridBagLayout());
		add(new JButton("I am a Button"));
		setContentPane(panel);
		setLayout(new GridBagLayout());
		splitScreenX((byte) 3);
		splitScreenY((byte) 3);
		align(ALIGN.CENTERONSCREEN);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setDefaultLookAndFeelDecorated(true);
	}

	public void align(ALIGN align) {
		if (getSize() != null) {
			switch (align) {
			case CENTERONSCREEN:
				setLocationRelativeTo(null);
				break;

			default:
				break;
			}
		}
	}

	public void init() {
		setVisible(true);
	}

	private void splitScreenX(byte number) {
		setSize(getScreen().width / number, getSize().height);
	}

	private void splitScreenY(byte number) {
		setSize(getSize().width, getScreen().height / number);
	}

	private void setFullScreen() {
		setExtendedState(JFrame.MAXIMIZED_BOTH);
	}

	private Dimension getScreen() {
		return Toolkit.getDefaultToolkit().getScreenSize();
	}

}
